package com.bk.cyxf.lf;

import _33._11._164._10.NetGridWebService.services.WebService.WebService;
import _33._11._164._10.NetGridWebService.services.WebService.WebServiceServiceLocator;

import com.bk.cyxf.log.LogManager;

import jt.classic.system.ISystem;
import jt.classic.system.SimpleAction;
import jt.classic.system.database.SystemDataSource;
import jt.classic.system.object.IObject;
import jt.classic.system.object.ObjectLCManager;
import jt.classic.system.object.ObjectManager;
import jt.classic.system.purview.PurviewManager;
import jt.classic.system.role.IRole;
import jt.classic.system.role.RoleManager;
import jt.classic.system.user.IUser;
import jt.classic.system.user.UserManager;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.limp.basework.SimpleBean4Table;
import org.limp.basework.Table;
import org.limp.basework.impl.CommonBean4HSQ;
import org.limp.basework.impl.SimpleBean4TableImpl;
import org.limp.basework.tools.BaseworkUtil;

import org.limp.mine.DataTrimmerI;
import org.limp.mine.DateTrimmer;
import org.limp.mine.Controller;
import org.limp.mine.Label;
import org.limp.mine.QueryJack;
import org.limp.mine.QueryJackFactory;
import org.limp.mine.StringTool;

import java.io.PrintWriter;
import java.sql.Connection;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.limp.mine.annex.AnnexInfo;
import org.limp.mine.annex.transactor.AnnexTransactorException;

import jt.classic.system.utils.AnnexTool;


/**
 * 来访办理
 *
 * @author lvt
 *
 */
public class LfblAction extends SimpleAction {
    /**
     * 来访办理
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward edit(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;
        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        String querykey = StringTool.checkString(request.getParameter(
                    "querykey"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String status = StringTool.checkString(info.get("BLSTATUS"));

                if (!status.equals("0")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "来访登记已在办理过程中,不能重复办理");
                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("querykey", querykey);
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lfbl");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访审批
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward editsp(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记访息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String status = StringTool.checkString(info.get("SHSTATUS"));

                if (status.equals("2")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "来访登记已办结,不能重复审批");
                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lxsp");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访派遣办理
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward deal(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        String status = StringTool.checkString(request.getParameter("BLSTATUS"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LF");

                    Map info = (Map) ((List) object.icontent(tbl)).get(0);

                    String lfid = StringTool.checkString(info.get("LFID"));

                    /*原办理状态*/
                    String orgsts = StringTool.checkString(info.get("BLSTATUS"));

                    /*来访类型*/
                    String LFTYPE = StringTool.checkString(info.get("LFTYPE"));

                    if (!orgsts.equals("0")) {
                        /*已办理事项,不能再次办理*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        /*自处理*/
                        String stsLabel = "自处理";

                        if (status.equals("2")) {
                            /*办理*/
                            stsLabel = "派遣办理";
                        } else if (status.equals("3")) {
                            /*上报*/
                            stsLabel = "上报处理";
                        } else if (status.equals("-1")) {
                            /*不予办理*/
                            stsLabel = "不予办理";
                        }

                        CommonBean4HSQ cbh = new CommonBean4HSQ(request);

                        SimpleBean4Table sbt = new SimpleBean4TableImpl("APP_LF",
                                cbh);

                        sbt.getResource().put("lfid", lfid);

                        sbt.getResource().put("PQRID", user.id());
                        sbt.getResource().put("PQRNAME", user.iname());
                        sbt.getResource().put("PQRGROUPID", user.igroup().id());
                        sbt.getResource().put("PQRGROUPNAME",
                            user.igroup().iname());

                        if (status.equals("-1") || status.equals("1")) {
                            sbt.getResource().put("LFSTATUS", "1");

                            String backInfo = StringTool.checkString(request.getParameter(
                                        "H_BACKINFO"));

                            /*信访办办理*/
                            SimpleBean4Table sbt1 = new SimpleBean4TableImpl(
                                    "APP_XFHANDLER");
                            sbt1.getResource().put("H_GROUPID",
                                user.igroup().id());
                            sbt1.getResource().put("H_GROUPNAME",
                                user.igroup().iname());
                            sbt1.getResource().put("XFID", lfid);
                            sbt1.getResource().put("XF_TYPE", "1");
                            sbt1.getResource().put("H_USERID", user.id());
                            sbt1.getResource().put("H_USERNAME", user.iname());
                            sbt1.getResource().put("H_STATUS", "1");
                            sbt1.getResource().put("H_BACKINFO", backInfo);
                            sbt1.getResource().put("H_DATE",
                                DateTrimmer.getYMDHMS());

                            BaseworkUtil util = new BaseworkUtil();
                            Map m = util.manualSave1(sbt1, conn);

                            manager.createSystemRelationObject(id,
                                "APP_XFHANDLER", (String) m.get("HID"));
                        } else if (status.equals("2")) {
                            String jbrgroupid = StringTool.checkString(request.getParameter(
                                        "H_GROUPID"));

                            String jbrgroupname = StringTool.checkString(request.getParameter(
                                        "H_GROUPNAME"));
                            
                            String[] idArray = jbrgroupid.split(",");
                            String[] nameArray = jbrgroupname.split(",");
                            
                            
                            BaseworkUtil util = new BaseworkUtil();
                            PurviewManager pm = new PurviewManager(conn);
                            RoleManager rm = new RoleManager(conn);
                            
                            for(int i= 0;i <idArray.length;i++){
                            	
	                            /*派遣科室办理*/
	                            SimpleBean4Table sbt1 = new SimpleBean4TableImpl(
	                                    "APP_XFHANDLER");
	
	                            /*添加处理科室ID*/
	                            sbt1.getResource().put("H_GROUPID", idArray[i]);
	
	                            /*添加处理科室名称*/
	                            sbt1.getResource().put("H_GROUPNAME", nameArray[i]);
	
	                            sbt1.getResource().put("XFID", lfid);
	                            sbt1.getResource().put("XF_TYPE", "1");
	                            sbt1.getResource().put("H_STATUS", "0");
	
	                            
	                            Map m = util.manualSave1(sbt1, conn);
	
	                            manager.createSystemRelationObject(id,
	                                "APP_XFHANDLER", (String) m.get("HID"));
	
	                            
                            }
                            
                            IRole role = null;
                        	
                            /*街乡信访办理负责人*/
                            if (LFTYPE.equals("0")) {
                                role = rm.getRoleByKey("jxpic");
                            }
                            /*区信访办理负责人*/
                            else if (LFTYPE.equals("1")) {
                                role = rm.getRoleByKey("qupic");
                            }

                            /*授权信访办理负责人可对来信进行办理*/
                            pm.insert(object.id(), object.iname(),
                                object.ikey(), "ISYS_OBJECT", 3, role.id(),
                                role.iname(), "role", user, false);
                        }

                        BaseworkUtil util = new BaseworkUtil();

                        util.manualUpdate1(sbt, conn);

                        LogManager lm = new LogManager(conn);

                        lm.log(user, lfid, "1", "lfcz", stsLabel);

                        /*上报*/
                        if (status.equals("3")) {
                        }

                        conn.commit();

                        request.setAttribute("result", "{success: true}");
                    }
                }
            }
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-3'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return mapping.findForward("result");
    }

    /**
     * 来访办理
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward edithdl(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lfid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("LFSTATUS"));

                if (status.equals("1")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "来访登记已办结,不能重复办理");
                    forward = mapping.findForward("error");
                } else {
//                    String sql = "SELECT * FROM APP_XFHANDLER WHERE XFID = ? AND XF_TYPE = ?";
//
//                    DataTrimmerI trimmer = new DataTrimmerI(conn);
//
//                    DataTrimmerI.DataItemList dil = trimmer.createDIL();
//                    dil.set(lfid);
//                    dil.set("1");

//                    Map hdlMap = trimmer.searchSingleData(sql, dil);
//
//                    String hdluserid = StringTool.checkString(hdlMap.get(
//                                "H_USERID"));
//
//                    IUser user = ISystem.getSessionUser(request);

//                    if (!hdluserid.equals("") && !hdluserid.equals(user.id())) {
//                        request.setAttribute("error", "来访已在办理过程中...");
//                        forward = mapping.findForward("error");
//                    } else {
//                        if (hdluserid.equals("")) {
//                            String hdlkey = StringTool.checkString(hdlMap.get(
//                                        "HID"));
//
//                            SimpleBean4Table sbt1 = new SimpleBean4TableImpl(
//                                    "APP_XFHANDLER");
//
//                            /*设置办理人ID*/
//                            sbt1.getResource().put("H_USERID", user.id());
//
//                            /*设置办理人姓名*/
//                            sbt1.getResource().put("H_USERNAME", user.iname());
//
//                            sbt1.getResource().put("HID", hdlkey);
//
//                            BaseworkUtil util = new BaseworkUtil();
//
//                            Map m = util.manualUpdate1(sbt1, conn);
//
//                            conn.commit();
//                        }

                        request.setAttribute("object", object);
                        request.setAttribute("wobject", object.iobject());
                        forward = mapping.findForward("lfhdl");
//                    }
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访科室办理
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward handle(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;
        CommonBean4HSQ cbh = new CommonBean4HSQ(request);
        Map param = cbh.getResource();
        String id = (String)param.get("id");
        String backInfo = (String)param.get("H_BACKINFO");
        
//        String id = StringTool.checkString(request.getParameter("id"));
//
//        String backInfo = StringTool.checkString(request.getParameter("H_BACKINFO"));
        
//        String clfsid = StringTool.checkString(request.getParameter("CLFSID"));
//
//        String clfs = StringTool.checkString(request.getParameter("CLFS"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LF");
                    Map info = (Map) ((List) object.icontent(tbl)).get(0);
                    String lfid = StringTool.checkString(info.get("LFID"));
                    String orgsts = StringTool.checkString(info.get("LFSTATUS"));
                    String pqrgroupid = StringTool.checkString(info.get("PQRGROUPID"));
                    

                    if (orgsts.equals("1")) {
                        /*已审批事项,不能再次审批*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        String sql = "SELECT HID FROM APP_XFHANDLER WHERE XFID = ? AND XF_TYPE = ? AND H_GROUPID = ?";

                        DataTrimmerI trimmer = new DataTrimmerI(conn);

                        DataTrimmerI.DataItemList dil = trimmer.createDIL();

                        dil.set(lfid);
                        dil.set(1);
                        dil.set(user.igroup().id());

                        Map hdlMap = trimmer.searchSingleData(sql, dil);

                        String hdlkey = StringTool.checkString(hdlMap.get("HID"));
                        
                        SimpleBean4Table sbt = new SimpleBean4TableImpl(
                        "APP_XFHANDLER", cbh);
                        
		                sbt.getResource().put("H_STATUS", "1");
		                sbt.getResource().put("H_BACKINFO", backInfo);
		                sbt.getResource().put("H_DATE", DateTrimmer.getYMDHMS());
		                sbt.getResource().put("HID", hdlkey);
		                sbt.getResource().put("H_USERID", user.id());
		                sbt.getResource().put("H_USERNAME", user.iname());
		
		                BaseworkUtil util = new BaseworkUtil();
                        //如果是派遣人科室（一般是信访办）需要判断其他科室是否已经办理完成，如果是其他科室则直接保存办理结果
                        if( user.igroup().id().equals(pqrgroupid)){
                        	//暂时不对派遣办理的科室办理情况作判断-----start
                           /*
                        	//判断派遣办理的科室是否办理完成
                            String sql_2 = "SELECT * FROM APP_XFHANDLER WHERE XFID = ? AND XF_TYPE = ? AND H_GROUPID != ?";
                            DataTrimmerI.DataItemList dil_2 = trimmer.createDIL();
                            dil_2.set(lfid);
                            dil_2.set("1");
                            dil_2.set(user.igroup().id());	
                            List<Map> handlerList = trimmer.searchMultiData(sql_2, dil_2);
                            boolean handlerResult = true;
                            for(Map m: handlerList){
                            	String h_status = StringTool.checkString(m.get("H_STATUS"));
                            	if("0".equals(h_status)){
                            		//只要有一个科室为办理完成则该条来访记录的科室办理环节未完成
                            		handlerResult = false;
                            	}
                            }
                            
                            //其他科室都办理完成并且当前用户所在科室与派遣人科室一致，由该科室结束办理
                            if(handlerResult){
                            	util.manualUpdate1(sbt, conn);
                            	
                                SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LF");

                                sb.getResource().put("LFSTATUS", "1");

                                sb.getResource().put("lfid", lfid);

                                util.manualUpdate1(sb, conn);
                                request.setAttribute("result", "{success: true}");
                            }else{
                            	//返回错误信息
                            	request.setAttribute("result", "{success: \"false\",msg:\"经办部门未办理完\"'}");
                            }*/
//                        	暂时不对派遣办理的科室办理情况作判断-----end
                        	util.manualUpdate1(sbt, conn);
                        	
                            SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LF");

                            sb.getResource().put("LFSTATUS", "1");

                            sb.getResource().put("lfid", lfid);

                            util.manualUpdate1(sb, conn);
                            request.setAttribute("result", "{success: true}");
                        
                        	
                        }else{
                        	util.manualUpdate1(sbt, conn);
                        	request.setAttribute("result", "{success: true}");
                        }



                        LogManager lm = new LogManager(conn);

                        lm.log(user, lfid, "1", "lfhandle", "");
                        
                        
                        //判断一人多问题情况，非信访办用户全部处理完毕后合成新记录；对正常用户的影响，都得判断app_lf表的记录数
                        if(!ISystem.matchrole(user, "jxxfbbgsuser")){
                        	
                        	String lf_sjs = StringTool.checkString(info.get("LF_SJS"));
                        	if(!"".equals(lf_sjs)){
	                        	String sql_lf = "SELECT * FROM APP_LF WHERE LF_SJS=?";
	                        	DataTrimmerI.DataItemList di2 = trimmer.createDIL();
	                        	di2.set(lf_sjs);
	                        	List<Map>  resultList= trimmer.searchMultiData(sql_lf, di2);
	                        	if(resultList!=null){
	                        		int len = resultList.size();
	                        		if(len>1){
	                        			String dj_objid = "";
	                        			String ts_lfid = StringTool.checkString(info.get("TS_LFID"));
	                        			if("".equals(ts_lfid)){
	                        				dj_objid = id;
	                        				
	                        			}else{
	                        				dj_objid = ts_lfid;
	                        				
	                        			}
	                        			
	                        			String total_status="",total_nrid="",total_nrname="",total_jdr="";
	                        			String total_ssd="",total_ssdname="",total_qtsdname="",total_bfydw="";
	                        			String total_hgroupname="",total_hgroupid="",total_nr="",total_ldps="";
	                        			String total_ldpsj="",total_jbd="",total_temp_ssd="",total_temp_ssdname="";
	                        			String dj_total_ssdname="";
	                        			String total_lfid="";
	                        			List<Map>  resultList_handler = null;
	                        			total_lfid = this.getTotalValue(total_lfid, resultList,"LFID");
	                        			if(!"".equals(total_lfid)){
		                        			String sql_handler="SELECT H_STATUS FROM APP_XFHANDLER WHERE XFID IN("+total_lfid+") AND H_STATUS<>?";
	                        				//String sql_handler="SELECT H_STATUS FROM APP_XFHANDLER WHERE XFID IN (?) AND H_STATUS<>?";
		                        			DataTrimmerI.DataItemList di_handler = trimmer.createDIL();
		                        			//di_handler.set(total_lfid);
		                        			di_handler.set(2);
		                        			resultList_handler= trimmer.searchMultiData(sql_handler, di_handler);
		                        			total_status = this.getTotalValue(total_status,resultList_handler,"H_STATUS");
		                        			
	                        			}
	                        			
	                        			if(total_status.indexOf("0")>-1){}
	                        			else{
	                        				//******说明多问题各部门已办理完毕；合成新记录并送给信访办******
	                        				
	                        				
	                        				String djrid = StringTool.checkString(info.get("DJRID"));
	                        				UserManager um = new UserManager(conn);
	                        				IUser xfb_user = um.getUserById(djrid);
	                        				IObject dj_object = lcmanager.getObjectById(dj_objid);//用登记id取得原登记的对象
	                        				IObject xfb_object = manager.copy(dj_object, request);//复制原登记的对象
	                        				//******************合成来访表APP_LF相应的字段****************************
	                        				for(Map m : resultList){
		                        				
		                        				String nrid = StringTool.checkString(m.get("NRID"));
		                        				String nrname = StringTool.checkString(m.get("NRNAME"));
		                        				String jdr = StringTool.checkString(m.get("JDR"));
		                        				String ssd = StringTool.checkString(m.get("SSD"));
		                        				String ssdname = StringTool.checkString(m.get("SSDNAME"));
		                        				String qtsdname = StringTool.checkString(m.get("QT_SDNAME"));
		                        				String bfydw = StringTool.checkString(m.get("BFYDW"));
		                        				
		                        				total_nrid = this.getSingleFiledValue(total_nrid,nrid);
		                        				total_nrname = this.getSingleFiledValue(total_nrname,nrname);
		                        				total_jdr = this.getSingleFiledValue(total_jdr,jdr);
		                        				total_qtsdname = this.getSingleFiledValue(total_qtsdname,qtsdname);
		                        				total_bfydw = this.getSingleFiledValue(total_bfydw,bfydw);
		                        				
		                        				total_temp_ssd = this.getMultiFiledValue(total_temp_ssd, ssd);
		                        				total_temp_ssdname = this.getMultiFiledValue(total_temp_ssdname, ssdname);
		                        				//修改原来合成前的多条APP_LF表的来访状态
		                        				SimpleBean4Table sbt_olf = new SimpleBean4TableImpl("APP_LF");
		                        				sbt_olf.getResource().put("LFSTATUS", "1");
		                        				sbt_olf.getResource().put("lfid",m.get("LFID"));
		                        				util.manualUpdate1(sbt_olf, conn);
		                        				
		                        				
		                        			}
	                        				
	                        				//********************************************************************
	                        				BaseworkUtil util_hc = new BaseworkUtil();
	                        				Table tb_lf = xfb_object.iobject().itable("APP_LF");
	                        				Map hc_info = (Map) ((List) xfb_object.icontent(tb_lf)).get(0);
	                        				 
	                        				String hc_lfid = StringTool.checkString(hc_info.get("LFID"));
	                        				String dj_ssdname = StringTool.checkString(info.get("SSDNAME"));
	                        				String start_ssdname = dj_ssdname.substring(0,dj_ssdname.indexOf("->")+2);
	                        				
	                        				total_ssd = this.getMultiTotal(total_temp_ssd.split(","));
	                        				total_ssdname = this.getMultiTotal(total_temp_ssdname.split(","));
	                        				
	                        				SimpleBean4Table sbt_lf = new SimpleBean4TableImpl("APP_LF");
	                        				sbt_lf.getResource().put("lfid", hc_lfid);
	                        				sbt_lf.getResource().put("NRID", total_nrid);
	                        				sbt_lf.getResource().put("NRNAME", total_nrname);
	                        				sbt_lf.getResource().put("JDR", total_jdr);
	                        				sbt_lf.getResource().put("SSD", ","+total_ssd);
	                        				sbt_lf.getResource().put("SSDNAME", start_ssdname+total_ssdname);
	                        				sbt_lf.getResource().put("QT_SDNAME", total_qtsdname);
	                        				sbt_lf.getResource().put("BFYDW", total_bfydw);
	                        				sbt_lf.getResource().put("LFBS", "1");
	                        				//sbt_lf.getResource().put("XFTIME", DateTrimmer.getYMDHMS());
	                        				util_hc.manualUpdate1(sbt_lf, conn);
	                        				//**********复制过来后查找到APP_XFHANDLER表中H_STATUS为2的记录主键，删除ISYS_OBJECT_RELATION中obj_pkid为其的记录**start**
	                        				//**********目的是为了合成后送给信访办的记录可出现办理超链******************************************
	                        				SimpleBean4Table gl_handler = new SimpleBean4TableImpl("APP_XFHANDLER");
	                        				List list_gl_handler = (List)xfb_object.icontent(gl_handler.getTable());
	                        				if (list_gl_handler != null && !list_gl_handler.isEmpty()){
	                        					for(int a = 0; a < list_gl_handler.size(); a++){
	                        						Map info_gl_handler = (Map)list_gl_handler.get(a);
	                        						String h_status = (String)info_gl_handler.get("H_STATUS");
	                        						if("2".equals(h_status)){
	                        							
	                        							String del_sql = "DELETE FROM ISYS_OBJECT_RELATION WHERE ID=?" +
	                        									"AND OBJ_PKID=?";
	                        							DataTrimmerI.DataItemList di_del_handler = trimmer.createDIL();
	                        							di_del_handler.set(xfb_object.id());
	                        							di_del_handler.set(info_gl_handler.get("HID"));
	                        							trimmer.execute(del_sql, di_del_handler);
	                        							
	                        							String del_xfb_handlerSql = "DELETE FROM APP_XFHANDLER WHERE HID=?";
	                        							DataTrimmerI.DataItemList di_del_handler_xfb = trimmer.createDIL();
	                        							di_del_handler_xfb.set(info_gl_handler.get("HID"));
	                        							trimmer.execute(del_xfb_handlerSql, di_del_handler_xfb);
	                        							break;
	                        						}
	                        					}
	                        					
	                        				}
	                        				
	                        				AnnexTool old_fj = new AnnexTool(conn);
	                        				//******************************************************************************************************stop****
	                        				//*****************************更改复制过来后APP_XFHANDLER表的xfid为合成后的lfid*****begin**************
	                        				SimpleBean4Table hc_handler = new SimpleBean4TableImpl("APP_XFHANDLER");
	                        				List list_handler = (List)xfb_object.icontent(hc_handler.getTable());
	                        				if (list_handler != null && !list_handler.isEmpty()){
	                        					for (int i = 0; i < list_handler.size(); i++){
	                        						Map info_handler = (Map)list_handler.get(i);
	                        						SimpleBean4Table sbt_handler_hc = new SimpleBean4TableImpl("APP_XFHANDLER");
	                        						sbt_handler_hc.getResource().put("XFID", hc_lfid);
	                        						sbt_handler_hc.getResource().put("HID", info_handler.get("HID"));
	                        						util_hc.manualUpdate1(sbt_handler_hc, conn);
	                        						//***************取得复过来的附件，修改其外键为合成的hid***************
	                        						/*AnnexInfo[] ais_hffj_hc = (AnnexInfo[])info_handler.get("HFFJ");
		                        					AnnexInfo ai_hc = (ais_hffj_hc != null ? ais_hffj_hc[0] : null);
		                        					if(ai_hc!=null){
		                        						//****修改附件外键为合成的hid
		                        					}*/
	                        						//**************************************************************
	                        					}
	                        				}
	                        				//******************************************************************************end****************
	                        				//*********过滤原登记记录的办理人记录后插入到新合成的办理中对APP_XFHANDLER表的insert操作***begin**************
	                        				String dj_lfid="";
	                        				Table tb_lfdj = dj_object.iobject().itable("APP_LF");
	                        				Map dj_info = (Map) ((List) dj_object.icontent(tb_lfdj)).get(0);
	                        				dj_lfid = StringTool.checkString(dj_info.get("LFID"));
	                        				List<Map>  resultList_gldj_handler = null;
	                        				String gldj_handlerSql = "SELECT * FROM APP_XFHANDLER WHERE H_STATUS=1 AND  XFID IN("+total_lfid+") AND XFID<>?";
	                        				DataTrimmerI.DataItemList di_gldj_handler = trimmer.createDIL();
	                        				di_gldj_handler.set(dj_lfid);
	                        				resultList_gldj_handler= trimmer.searchMultiData(gldj_handlerSql, di_gldj_handler);
	                        				String total_hid="",total_fjname="",total_fjid="";
	                        				List total_handler_fjArray = new  ArrayList();
	                        				
	                        				for(Map m : resultList_gldj_handler){
	                        					//取得过滤登记后办理表对应的回复附件必须得通过AnnextTool获取
	                        					String old_hid = (String)m.get("HID");
	                        					AnnexInfo ai_handler = old_fj.getAnnex(old_hid, "APP_XFHANDLER", "HFFJ");
	    										SimpleBean4Table hc_sbt = new SimpleBean4TableImpl(
	                    								"APP_XFHANDLER");
	                    						hc_sbt.getResource().put("XFID", hc_lfid);
	                    						hc_sbt.getResource().put("XF_TYPE", "1");
	                    						hc_sbt.getResource().put("H_USERID",m.get("H_USERID"));
	                    						hc_sbt.getResource().put("H_USERNAME",m.get("H_USERNAME"));
	    										/* 添加处理科室ID */
	                    						hc_sbt.getResource().put("H_GROUPID", m.get("H_GROUPID"));
	                    						/* 添加处理科室名称 */
	                    						hc_sbt.getResource().put("H_GROUPNAME", m.get("H_GROUPNAME"));
	                    						hc_sbt.getResource().put("H_STATUS", "1");
	                    						hc_sbt.getResource().put("H_BACKINFO", m.get("H_BACKINFO"));
	                    						hc_sbt.getResource().put("H_DATE", m.get("H_DATE"));
	    										Map rsm = util_hc.manualSave1(hc_sbt, conn);
	    	
	    										manager.createSystemRelationObject(xfb_object.id(),
	    												"APP_XFHANDLER", (String) rsm.get("HID"));
	    										//****************取得除登记以外办理表的附件id，名称和APP_XFHANDLER的主键********************begin*******
	    										if(ai_handler!=null){
		    										if("".equals(total_hid)){
		    											total_hid = (String) rsm.get("HID");
		    											total_fjname = ai_handler.getName();
		    											total_fjid = ai_handler.getID();
		    										}else{
		    											total_hid = total_hid+";"+(String) rsm.get("HID");
		    											total_fjname = total_fjname+";"+ai_handler.getName();
		    											total_fjid = total_fjid+";"+ai_handler.getID();
		    										}
		    										//****取得除登记以外办理表对应的所有附件****
		    										total_handler_fjArray.add(ai_handler);
	    										}
	    										
		                        				
		                        				//*********************************************************end*******
	    									
	                        				}
	                        				//**************************************************************************************end***********
	                        				//****************************************合成记录派遣给信访办用户***********start******
	                        				SimpleBean4Table hc_xfb_sbt = new SimpleBean4TableImpl("APP_XFHANDLER");
	                        				hc_xfb_sbt.getResource().put("XFID", hc_lfid);
	                        				hc_xfb_sbt.getResource().put("XF_TYPE", "1");
	                        				hc_xfb_sbt.getResource().put("H_USERID",djrid);
	                        				hc_xfb_sbt.getResource().put("H_USERNAME",xfb_user.iname());
    										/* 添加处理科室ID */
	                        				hc_xfb_sbt.getResource().put("H_GROUPID", xfb_user.igroup().id());
                    						/* 添加处理科室名称 */
	                        				hc_xfb_sbt.getResource().put("H_GROUPNAME", xfb_user.igroup().iname());
	                        				hc_xfb_sbt.getResource().put("H_STATUS", "0");
	                        				Map rsm_xfb = util_hc.manualSave1(hc_xfb_sbt, conn);
	                        				manager.createSystemRelationObject(xfb_object.id(),
    												"APP_XFHANDLER", (String) rsm_xfb.get("HID"));
	                        				
	                        				//****给信访办授权*******************************
	                        				RoleManager rm = new RoleManager(conn);
	                        				IRole role = rm.getRoleByKey("jxxfbuser");
	                        				IRole xfManager = rm.getRoleByKey("xfmanager");
	                        				PurviewManager pm = new PurviewManager(conn);
	                        				/* 对信访办角色进行授权,可以对该来访进行办理 */
	                        				pm.insert(xfb_object.id(), xfb_object.iname(), xfb_object.ikey(), "ISYS_OBJECT", 3,
	                        						role.id(), role.iname(), "role", user, false);

	                        				/* 对信访系统管理员角色进行授权,可以对来信进行编辑\删除\查阅 */
	                        				pm.insert(xfb_object.id(), xfb_object.iname(), xfb_object.ikey(), "ISYS_OBJECT", 3,
	                        						xfManager.id(), xfManager.iname(), "role", user, false);
	                        				//************************************************************************stop************************
	                        				//*********************合成附件分为来访表APP_LF的LDPSJ和JBD以及handler表APP_HANDLER的HFFJ**************************
	                        				//**********************取得原来访登记中的LDPSJ和JBD以及原办理表的附件记录的附件名称****************************************************
	                        				
	                        				/*AnnexInfo fj_ldpsj = null;
	                        				AnnexInfo fj_jbd = null;
	                        				AnnexInfo fj_ldpsj_hc = null;
	                        				AnnexInfo fj_jbd_hc = null;
	                        				String total_handler_djfjname="";
	                        				
	                        				if(dj_info!=null){
	                        					AnnexInfo[] ais_ldpsj = (AnnexInfo[])dj_info.get("LDPSJ");
	                        					AnnexInfo[] ais_jbd = (AnnexInfo[])dj_info.get("JBD");
	                        					fj_ldpsj = (ais_ldpsj != null ? ais_ldpsj[0] : null); 
	                        					fj_jbd = (ais_jbd != null ? ais_jbd[0] : null);
	                        				}
	                        				
	                        				SimpleBean4Table dj_handler = new SimpleBean4TableImpl("APP_XFHANDLER");
	                        				List list_dj_handler = (List)dj_object.icontent(dj_handler.getTable());
	                        				if (list_dj_handler != null && !list_dj_handler.isEmpty()){
	                        					for (int kk = 0; kk < list_dj_handler.size(); kk++){
	                        						Map info_handler_dj = (Map)list_dj_handler.get(kk);
		                        					AnnexInfo[] ais_hffj = (AnnexInfo[])info_handler_dj.get("HFFJ");
		                        					AnnexInfo ai = (ais_hffj != null ? ais_hffj[0] : null);
		                        					if(ai!=null){
			                        					if("".equals(total_handler_djfjname)){
			                        						total_handler_djfjname = ai.getName();
			                        						
			                        					}else{
			                        						total_handler_djfjname = total_handler_djfjname+";"+ai.getName();
			                        						
			                        					}
			                        					
		                        					}
	                        					}
	                        				}
	                        				//***********修改登记记录复制过来后的附件外键id*************************
	                        				if(hc_info!=null){
	                        					AnnexInfo[] ais_ldpsj_hc = (AnnexInfo[])hc_info.get("LDPSJ");
	                        					AnnexInfo[] ais_jbd_hc = (AnnexInfo[])hc_info.get("JBD");
	                        					fj_ldpsj_hc = (ais_ldpsj_hc != null ? ais_ldpsj_hc[0] : null); 
	                        					fj_jbd_hc = (ais_jbd_hc != null ? ais_jbd_hc[0] : null);
	                        				}
	                        				if(fj_ldpsj_hc!=null){
	                        					//this.getHch_newFj(trimmer, hc_lfid, fj_ldpsj);
	                        					fj_ldpsj_hc.setObjectID(hc_lfid);
	                        				}
	                        				
	                        				if(fj_jbd_hc!=null){
	                        					//this.getHch_newFj(trimmer, hc_lfid, fj_jbd);
	                        					fj_jbd_hc.setObjectID(hc_lfid);
	                        				}
	                        				//****************取得除登记以外来访记录的附件********************begin********************
	                        				String total_gl_ldpsj_fjname="",total_gl_jbd_fjname="";
	                        				List total_gl_ldpsj_fjArray = new  ArrayList();
	                        				List total_gl_jbd_fjArray = new  ArrayList();
	                        				List<Map> resultList_gldj_lf = null;
	                        				String gldj_lfSql = "SELECT * FROM APP_LF WHERE LFID IN("+total_lfid+") AND LFID<>?";
	                        				DataTrimmerI.DataItemList di_gldj_lf = trimmer.createDIL();
	                        				di_gldj_lf.set(dj_lfid);
	                        				resultList_gldj_lf = trimmer.searchMultiData(gldj_lfSql, di_gldj_lf);
	                        				
	                        				
	                        				total_gl_ldpsj_fjArray = this.gl_getFjTotal(resultList_gldj_lf,"APP_LF","LDPSJ", 
	                        						fj_ldpsj,old_fj);
	                        				
	                        				
	                        				total_gl_jbd_fjArray = this.gl_getFjTotal(resultList_gldj_lf,"APP_LF","JBD", 
	                        						fj_jbd,old_fj);
	                        				
	                        				
	                        				
	                        				
	                        				
	                        				//****取得除登记记录以外的的来访附件过滤相同名称的附件后设置外键再复制************
	                        				for(int mm=0;mm<total_gl_ldpsj_fjArray.size();mm++){
	                        					if(total_gl_ldpsj_fjArray.get(mm)!=null){
	                        					   
	                        						AnnexInfo ldpsj_fj = (AnnexInfo)total_gl_ldpsj_fjArray.get(mm);
	                        						
	                        						ldpsj_fj.setObjectID(hc_lfid);
	                        						old_fj.copyAnnex(ldpsj_fj);
	                        						
	                        					}
	                        				}
	                        				for(int nn=0;nn<total_gl_jbd_fjArray.size();nn++){
	                        					if(total_gl_jbd_fjArray.get(nn)!=null){
	                        					   
	                        						AnnexInfo jbd_fj = (AnnexInfo)total_gl_jbd_fjArray.get(nn);
	                        						
	                        						jbd_fj.setObjectID(hc_lfid);
	                        						old_fj.copyAnnex(jbd_fj);
	                        						
	                        					}
	                        				}*/
	                        				
	                        				String total_myfj="";
	                        				if(!"".equals(total_fjname)){
		                        				String[] total_gldj_fjnameArray = total_fjname.split(";");
		                        				String[] total_gldj_fjidArray = total_fjid.split(";");
		                        				String[] total_gldj_hidArray = total_hid.split(";");
		                        				for(int aa=0;aa<total_gldj_fjnameArray.length;aa++){
		                        					//if((";"+total_handler_djfjname+";").indexOf(";"+total_gldj_fjnameArray[aa]+";")==-1){
		                        						//****修改外键id后复制附件****************
		                        						AnnexInfo handler_fj = (AnnexInfo)total_handler_fjArray.get(aa);
		                        						handler_fj.setObjectID(total_gldj_hidArray[aa]);
		                        						old_fj.copyAnnex(handler_fj);
		                        						
		                        						
		                        					//}
		                        				}
	                        				}
	                        				
	                        				
	                        				
	                        				
	                        					
	                        				//***********************************************************stop*********************
	                        				//************************************************************************************************
	                        				//*************对来访表附件新的处理*****************************************
	                        				if(!"".equals(total_lfid)){
	                        					List lf_list = new ArrayList();
	                        					String[] total_lfidArray = total_lfid.split(",");
	                        					for(int i=0;i<total_lfidArray.length;i++){
			                        				String total_my_lfid="",total_groupname="";
			                        				HashMap map = new HashMap();
			                        				List<Map>  resultList_total_handler = null;
				                        			String handel_total_sql="SELECT * FROM APP_XFHANDLER WHERE XFID=? AND H_STATUS=?";
			                        				DataTrimmerI.DataItemList di_total_handler = trimmer.createDIL();
				                        			di_total_handler.set(total_lfidArray[i]);
				                        			di_total_handler.set(1);
				                        			resultList_total_handler= trimmer.searchMultiData(handel_total_sql, di_total_handler);
				                        			for(Map m : resultList_total_handler){
				                        			    String xfid = StringTool.checkString(m.get("XFID"));
				                        				String groupname = StringTool.checkString(m.get("H_GROUPNAME"));
				                        				if(xfid.equals(total_lfidArray[i])){
				                        					if("".equals(total_groupname)){
				                        						total_groupname = groupname;
				                        					}else{
				                        						total_groupname = total_groupname+";"+groupname;
				                        					}
				                        				}else{
				                        					total_groupname = groupname;
				                        				}
				                        				
				                        			}
				                        			//******获取附件********begin**********
				                        			AnnexInfo ldpsj_fj = old_fj.getAnnex(total_lfidArray[i], "APP_LF", "LDPSJ");
				                        			AnnexInfo jbd_fj = old_fj.getAnnex(total_lfidArray[i], "APP_LF", "JBD");
				                        			//*********************end***********
				                        			map.put("lfid", total_lfidArray[i]);
				                        			map.put("groupname", total_groupname);
				                        			map.put("ldpsj_fj", ldpsj_fj);
				                        			map.put("jbd_fj", jbd_fj);
				                        			lf_list.add(map);
				                        			
				                        			
			                        			}
	                        					//***把附件写成一定得格式********
	                        					String annex_ldpsj="",annex_jbd="",single_total_ldpsj_name="",single_total_jbd_name="";
			                        			for(int k=0;k<lf_list.size();k++){
			                        				String total_ldpsj_name="",total_jbd_name="";
			                        				HashMap lf_map = (HashMap)lf_list.get(k);
			                        				String groupname = (String)lf_map.get("groupname");
			                        				AnnexInfo ldpsj_fj = (AnnexInfo)lf_map.get("ldpsj_fj");
			                        				AnnexInfo jbd_fj = (AnnexInfo)lf_map.get("jbd_fj");
			                        				if(groupname.indexOf(";")>-1){
			                        					String[] total_nameArray = groupname.split(";");
			                        					for(int j=0;j<total_nameArray.length;j++){
			                        						String fjnr_ldpsj="",fjnr_jbd="";
			                        						if(ldpsj_fj!=null){
				                        						fjnr_ldpsj = "<span tp=\"annex_ldpsj\" id=\""+ldpsj_fj.getID()+"\">"
				                        						+total_nameArray[j]+": " +ldpsj_fj.getName()+"</span>";
			                        						}
			                        						
			                        						if(jbd_fj!=null){
				                        						fjnr_jbd = "<span tp=\"annex_jbd\" id=\""+jbd_fj.getID()+"\">"
				                        						+total_nameArray[j]+": " +jbd_fj.getName()+"</span>";
			                        						}
			                        						
			                        						if("".equals(total_ldpsj_name)){
			                        							total_ldpsj_name = fjnr_ldpsj;
			                        						}else{
			                        							total_ldpsj_name = total_ldpsj_name+"      "+fjnr_ldpsj;
			                        						}
			                        						
			                        						if("".equals(total_jbd_name)){
			                        							total_jbd_name = fjnr_jbd;
			                        						}else{
			                        							total_jbd_name = total_jbd_name+"      "+fjnr_jbd;
			                        						}
			                        					}
			                        					annex_ldpsj = total_ldpsj_name;
			                        					annex_jbd = total_jbd_name;
			                        				}else{
			                        					String nr_psj="",nr_jbd="",nr_psj_new="",nr_jbd_new="";
			                        					if(ldpsj_fj!=null){
			                        						nr_psj = "<span tp=\"annex_ldpsj\" id=\""+ldpsj_fj.getID()+"\">"+ldpsj_fj.getName()+"</span>";
			                        						nr_psj_new ="<span tp=\"annex_ldpsj\" id=\""+ldpsj_fj.getID()+"\">"
			                        						+groupname+": "+ldpsj_fj.getName()+"</span>";
			                        					}
			                        					if(jbd_fj!=null){
			                        						nr_jbd = "<span tp=\"annex_jbd\" id=\""+jbd_fj.getID()+"\">"+jbd_fj.getName()+"</span>";
			                        						nr_jbd_new ="<span tp=\"annex_jbd\" id=\""
			                        						+jbd_fj.getID()+"\">"
			                        						+groupname+": "+jbd_fj.getName()+"</span>";
			                        					}
			                        					if("".equals(single_total_ldpsj_name)){
			                        						single_total_ldpsj_name = groupname;
			                        						annex_ldpsj = annex_ldpsj+"      "+nr_psj_new;
			                        					}else{
			                        						if(single_total_ldpsj_name.equals(groupname)){
			                        							annex_ldpsj = annex_ldpsj+"      "+nr_psj;
			                        						}else{
			                        							annex_ldpsj = annex_ldpsj+"      "+nr_psj_new;
			                        						}
			                        						
			                        					}
			                        					
			                        					if("".equals(single_total_jbd_name)){
			                        						single_total_jbd_name = groupname;
			                        						annex_jbd = annex_jbd+"      "+nr_jbd_new;
			                        					}else{
			                        						if(single_total_jbd_name.equals(groupname)){
			                        							annex_jbd = annex_jbd+"      "+nr_jbd;
			                        						}else{
			                        							annex_jbd = annex_jbd+"      "+nr_jbd_new;
			                        						}
			                        						
			                        					}
			                        					
			                        				}
			                        				
			                        			}
			                        			
			                        			sbt_lf.getResource().put("lfid", hc_lfid);
		                        				sbt_lf.getResource().put("FJNR1", annex_ldpsj);
		                        				sbt_lf.getResource().put("FJNR2", annex_jbd);
		                        				util_hc.manualUpdate1(sbt_lf, conn);
			                        			
		                        			}
	                        				
	                        				
	                        				//*****************************************************************
	                        				
	                        			}
	                        		}
	                        	}
	                        	
                        	}
                        
                        }
                        
                        
                        conn.commit();

                        
                    }
                }
            }

            forward = mapping.findForward("result");
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-4'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复查
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward editfc(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lxid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("FCSTATUS"));

                if (!status.equals("-1")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "不能重复进行复查办理");
                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lffc");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复查派遣
     * <p>
     *    安排来访复查办理人员
     * </p>
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward savefc(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LF");

                    Map info = (Map) ((List) object.icontent(tbl)).get(0);

                    String lfid = StringTool.checkString(info.get("LFID"));

                    String orgsts = StringTool.checkString(info.get("FCSTATUS"));

                    if (orgsts.equals("0")) {
                        /*已复查事项,不能再次复查*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        String fcUserId = StringTool.checkString(request.getParameter(
                                    "FC_USERID"));

                        String fcBLDate = StringTool.checkString(request.getParameter(
                                    "FC_DATE"));

                        UserManager um = new UserManager(conn);

                        /*复查办理人*/
                        IUser fcUser = um.getUserById(fcUserId);

                        SimpleBean4Table sbt = new SimpleBean4TableImpl(
                                "APP_XFFC");

                        sbt.getResource().put("XFID", lfid);
                        sbt.getResource().put("XF_TYPE", "1");
                        sbt.getResource().put("FC_STATUS", "0");
                        sbt.getResource().put("FC_USERID", fcUser.id());
                        sbt.getResource().put("FC_USERNAME", fcUser.iname());
                        sbt.getResource().put("FC_GROUPID", fcUser.igroup().id());
                        sbt.getResource().put("FC_GROUPNAME",
                            fcUser.igroup().iname());
                        sbt.getResource().put("FC_DATE", fcBLDate);

                        BaseworkUtil util = new BaseworkUtil();

                        Map fcMap = util.manualSave1(sbt, conn);

                        String foid = (String) fcMap.get("FCID");

                        ObjectManager om = new ObjectManager(conn);
                        om.createSystemRelationObject(id, "APP_XFFC", foid);

                        SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LF");

                        sb.getResource().put("LFSTATUS", "0");

                        sb.getResource().put("FCSTATUS", "0");

                        sb.getResource().put("lfid", lfid);

                        util.manualUpdate1(sb, conn);

                        PurviewManager pm = new PurviewManager(conn);

                        /*授权信访复查负责人可对来信进行复查办理*/
                        pm.insert(object.id(), object.iname(), object.ikey(),
                            "ISYS_OBJECT", 3, fcUser.id(), fcUser.iname(),
                            "uesr", user, false);

                        LogManager lm = new LogManager(conn);

                        lm.log(user, lfid, "0", "lffccz", "");

                        conn.commit();

                        request.setAttribute("result", "{success: true}");
                    }
                }
            }

            forward = mapping.findForward("result");
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-4'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复查办理
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward blfc(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        IUser user = ISystem.getSessionUser(request);

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            ObjectManager om = new ObjectManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else if (om.purview(id, user) < 2) {
                request.setAttribute("error", "您没有复查办理权限,无法进行复查办理");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lxid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("FCSTATUS"));

                if (status.equals("-1")) {
                    request.setAttribute("error", "该来访不能进行复查办理");

                    forward = mapping.findForward("error");
                } else if (status.equals("1")) {
                    request.setAttribute("error", "来访已经复查办理结束,不能重复复查");

                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lffcbl");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复查办理
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward saveblfc(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        CommonBean4HSQ cbh = new CommonBean4HSQ(request);

        String id = StringTool.checkString(cbh.getResource().get("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LF");

                    Map info = (Map) ((List) object.icontent(tbl)).get(0);

                    String lfid = StringTool.checkString(info.get("LFID"));

                    String orgsts = StringTool.checkString(info.get("FCSTATUS"));

                    if (orgsts.equals("1")) {
                        /*已办理复查事项,不能重复复查*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        Table table = object.iobject().itable("APP_XFFC");

                        Map fcInfo = (Map) ((List) object.icontent(table)).get(0);

                        String fcid = StringTool.checkString(fcInfo.get("FCID"));

                        SimpleBean4Table sbt = new SimpleBean4TableImpl("APP_XFFC",
                                cbh);

                        sbt.getResource().put("FCID", fcid);
                        sbt.getResource().put("FC_STATUS", "1");
                        sbt.getResource().put("FC_BLDATE",
                            DateTrimmer.getYMDHMS());

                        BaseworkUtil util = new BaseworkUtil();

                        Map fcMap = util.manualUpdate1(sbt, conn);

                        SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LF");

                        sb.getResource().put("LFSTATUS", "1");

                        sb.getResource().put("FCSTATUS", "1");

                        sb.getResource().put("lfid", lfid);

                        util.manualUpdate1(sb, conn);

                        LogManager lm = new LogManager(conn);

                        lm.log(user, lfid, "0", "lffcbl", "");

                        conn.commit();

                        request.setAttribute("result", "{success: true}");
                    }
                }
            }

            forward = mapping.findForward("result");
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-4'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复核
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward editfh(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lfid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("FHSTATUS"));

                if (!status.equals("-1")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "不能重复进行复核办理");
                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lffh");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复核派遣
     * <p>
     *    安排来访复核办理人员
     * </p>
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward savefh(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LF");

                    Map info = (Map) ((List) object.icontent(tbl)).get(0);

                    String lfid = StringTool.checkString(info.get("LFID"));

                    String orgsts = StringTool.checkString(info.get("FHSTATUS"));

                    if (orgsts.equals("0")) {
                        /*已复核事项,不能再次复核*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        String fhUserId = StringTool.checkString(request.getParameter(
                                    "FH_USERID"));

                        String fhBLDate = StringTool.checkString(request.getParameter(
                                    "FH_DATE"));

                        UserManager um = new UserManager(conn);

                        /*复核办理人*/
                        IUser fcUser = um.getUserById(fhUserId);

                        SimpleBean4Table sbt = new SimpleBean4TableImpl(
                                "APP_XFFH");

                        sbt.getResource().put("XFID", lfid);
                        sbt.getResource().put("XF_TYPE", "1");
                        sbt.getResource().put("FH_STATUS", "0");
                        sbt.getResource().put("FH_USERID", fcUser.id());
                        sbt.getResource().put("FH_USERNAME", fcUser.iname());
                        sbt.getResource().put("FH_GROUPID", fcUser.igroup().id());
                        sbt.getResource().put("FH_GROUPNAME",
                            fcUser.igroup().iname());
                        sbt.getResource().put("FH_DATE", fhBLDate);

                        BaseworkUtil util = new BaseworkUtil();

                        Map fcMap = util.manualSave1(sbt, conn);

                        String foid = (String) fcMap.get("FHID");

                        ObjectManager om = new ObjectManager(conn);
                        om.createSystemRelationObject(id, "APP_XFFH", foid);

                        SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LF");

                        sb.getResource().put("LFSTATUS", "0");

                        sb.getResource().put("FHSTATUS", "0");

                        sb.getResource().put("lfid", lfid);

                        util.manualUpdate1(sb, conn);

                        PurviewManager pm = new PurviewManager(conn);

                        /*授权信访复查负责人可对来访进行复查办理*/
                        pm.insert(object.id(), object.iname(), object.ikey(),
                            "ISYS_OBJECT", 3, fcUser.id(), fcUser.iname(),
                            "uesr", user, false);

                        LogManager lm = new LogManager(conn);

                        lm.log(user, lfid, "0", "lffhcz", "");

                        conn.commit();

                        request.setAttribute("result", "{success: true}");
                    }
                }
            }

            forward = mapping.findForward("result");
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-4'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复核
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward blfh(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        IUser user = ISystem.getSessionUser(request);

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            ObjectManager om = new ObjectManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else if (om.purview(id, user) < 2) {
                request.setAttribute("error", "您没有复核办理权限,无法进行复核办理");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lxid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("FHSTATUS"));

                if (status.equals("-1")) {
                    request.setAttribute("error", "该来访不能进行复核办理");

                    forward = mapping.findForward("error");
                } else if (status.equals("1")) {
                    request.setAttribute("error", "来访已经复核办理结束,不能重复复核");

                    forward = mapping.findForward("error");
                } else {
                    request.setAttribute("object", object);
                    request.setAttribute("wobject", object.iobject());
                    forward = mapping.findForward("lffhbl");
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }

    /**
     * 来访复核办理
     * <p>
     *    安排来访复核办理人员
     * </p>
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward saveblfh(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        CommonBean4HSQ cbh = new CommonBean4HSQ(request);

        String id = StringTool.checkString(cbh.getResource().get("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectManager manager = new ObjectManager(conn);

            ObjectLCManager lcmanager = new ObjectLCManager(conn);

            IObject object = lcmanager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("result",
                    "{success: false, errCode : '-1'}");
            } else {
                IUser user = ISystem.getSessionUser(request);

                if (manager.purview(id, user) < 2) {
                    request.setAttribute("result",
                        "{success: false, errCode : '-2'}");
                } else {
                    Table tbl = object.iobject().itable("APP_LX");

                    Map info = (Map) ((List) object.icontent(tbl)).get(0);

                    String lxid = StringTool.checkString(info.get("LXID"));

                    String orgsts = StringTool.checkString(info.get("FHSTATUS"));

                    if (orgsts.equals("1")) {
                        /*已办理复核事项,不能重复复核*/
                        request.setAttribute("result",
                            "{success: false, errCode : '-3'}");
                    } else {
                        Table table = object.iobject().itable("APP_XFFH");

                        Map fhInfo = (Map) ((List) object.icontent(table)).get(0);

                        String fhid = StringTool.checkString(fhInfo.get("FHID"));

                        SimpleBean4Table sbt = new SimpleBean4TableImpl("APP_XFFH",
                                cbh);

                        sbt.getResource().put("FHID", fhid);
                        sbt.getResource().put("FH_STATUS", "1");
                        sbt.getResource().put("FH_BLDATE",
                            DateTrimmer.getYMDHMS());

                        BaseworkUtil util = new BaseworkUtil();

                        Map fhMap = util.manualUpdate1(sbt, conn);

                        SimpleBean4Table sb = new SimpleBean4TableImpl("APP_LX");

                        sb.getResource().put("LXSTATUS", "1");

                        sb.getResource().put("FHSTATUS", "1");

                        sb.getResource().put("lxid", lxid);

                        util.manualUpdate1(sb, conn);

                        LogManager lm = new LogManager(conn);

                        lm.log(user, lxid, "0", "lxfhbl", "");

                        conn.commit();

                        request.setAttribute("result", "{success: true}");
                    }
                }
            }

            forward = mapping.findForward("result");
        } catch (Exception ex) {
            conn.rollback();

            request.setAttribute("result", "{success: false, errCode : '-4'}");
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }
    
    
    /**
     * 来访办理生成页面初始化记录
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward lfneu(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        String id = StringTool.checkString(request.getParameter("id"));

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lfid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("LFSTATUS"));

                if (status.equals("1")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "来访登记已办结,不能重复办理");
                    forward = mapping.findForward("error");
                } else {
//                    String sql = "SELECT * FROM APP_XFHANDLER WHERE XFID = ? AND XF_TYPE = ?";
//
//                    DataTrimmerI trimmer = new DataTrimmerI(conn);
//
//                    DataTrimmerI.DataItemList dil = trimmer.createDIL();
//                    dil.set(lfid);
//                    dil.set("1");

//                    Map hdlMap = trimmer.searchSingleData(sql, dil);
//
//                    String hdluserid = StringTool.checkString(hdlMap.get(
//                                "H_USERID"));
//
//                    IUser user = ISystem.getSessionUser(request);

//                    if (!hdluserid.equals("") && !hdluserid.equals(user.id())) {
//                        request.setAttribute("error", "来访已在办理过程中...");
//                        forward = mapping.findForward("error");
//                    } else {
//                        if (hdluserid.equals("")) {
//                            String hdlkey = StringTool.checkString(hdlMap.get(
//                                        "HID"));
//
//                            SimpleBean4Table sbt1 = new SimpleBean4TableImpl(
//                                    "APP_XFHANDLER");
//
//                            /*设置办理人ID*/
//                            sbt1.getResource().put("H_USERID", user.id());
//
//                            /*设置办理人姓名*/
//                            sbt1.getResource().put("H_USERNAME", user.iname());
//
//                            sbt1.getResource().put("HID", hdlkey);
//
//                            BaseworkUtil util = new BaseworkUtil();
//
//                            Map m = util.manualUpdate1(sbt1, conn);
//
//                            conn.commit();
//                        }

                        request.setAttribute("object", object);
                        request.setAttribute("wobject", object.iobject());
                        forward = mapping.findForward("lfneu");
//                    }
                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }
    
    /**
     * 来访办理上报区平台
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward lfup(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        ActionForward forward = null;

        Connection conn = null;

        
        CommonBean4HSQ cbh = new CommonBean4HSQ(request);
        Map param = cbh.getResource();
        String id = (String)param.get("id");

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            ObjectLCManager manager = new ObjectLCManager(conn);

            IObject object = manager.getObjectById(id);

            if (object.iobject() == null) {
                request.setAttribute("error", "来访登记信息并不存在");

                forward = mapping.findForward("error");
            } else {
                Table tbl = object.iobject().itable("APP_LF");

                Map info = (Map) ((List) object.icontent(tbl)).get(0);

                String lfid = StringTool.checkString(info.get("LFID"));

                String status = StringTool.checkString(info.get("LFSTATUS"));

                if (status.equals("1")) {
                    /*已办理事项,不能再次办理*/
                    request.setAttribute("error", "来访登记已办结,不能重复办理");
                    forward = mapping.findForward("error");
                } else {
                		IUser user = ISystem.getSessionUser(request);
	    				String ssd = "";
	    				String nrid =  StringTool.checkString(info.get("NRID"));
	    				String total_ssd = StringTool.checkString(info.get("SSD"));
	    				String nr = StringTool.checkString(info.get("NR"));
	    				if(total_ssd.indexOf(",")>-1){
	    					String[] ssd_array = total_ssd.split(",");
	    					ssd = ssd_array[1];
	    				}else{
	    					ssd = total_ssd;
	    				}
                		SimpleBean4Table sbt_lf = new SimpleBean4TableImpl("APP_LF");
                		sbt_lf.getResource().put("LFTYPE", 1);
                		sbt_lf.getResource().put("lfid", lfid);
                		BaseworkUtil util = new BaseworkUtil();
                		util.manualUpdate1(sbt_lf, conn);
                		
                		//***********上报区平台处理及数据传递给V3平台******
                		WebServiceServiceLocator webServiceReporting =new WebServiceServiceLocator();
        				WebService w=webServiceReporting.getWebService();
        				String str = "{'opCode':'5001','v_case_type_id':'"+nrid+"','v_ext_prop9_str':'"+id+"','v_ext_prop10_str':'"+lfid+"'" +
        						",'v_region_id':'"+ssd+"','v_rpt_user_id':'"+user.ilogid()+"','v_case_desc':'"+nr+"'}";
        				String case_id=w.callService("",str);
        				System.out.println(str);
        				System.out.println(case_id);
                		//*******************************************
        				conn.commit();
                		request.setAttribute("object", object);
                        request.setAttribute("wobject", object.iobject());
                        request.setAttribute("result", "{success: true}");
                        forward = mapping.findForward("result");
                        

                }
            }
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
            forward = mapping.findForward("error");
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return forward;
    }
    
    /**
     * 取得多条记录某特定字段的所有值
     * @param total_obj
     * @param list
     * @param filed
     * @return
     */
    private String getTotalValue(String total_obj,List<Map> list,String filed){
    	for(Map m : list){
			if("".equals(total_obj)){
				total_obj = (String)m.get(filed);
			}else{
				total_obj = total_obj+","+(String)m.get(filed);
			}
		}
    	return total_obj;
    }
    
    /**
     * 取得过滤多条记录字段值为单个的所有值
     * @param total_obj
     * @param obj
     * @return
     */
    private String getSingleFiledValue(String total_obj,String obj){
    	
    	if("".equals(total_obj)){
    		total_obj = obj;
		}else{
			if(total_obj.indexOf(obj)>-1){}
			else{
				total_obj=total_obj+";"+obj;
			}
			
		}
    	return total_obj;
    }
    
    /**
     * 取得多条记录字段值为多个的所有值
     * @param total_obj
     * @param obj
     * @return
     */
    private String getMultiFiledValue(String total_obj,String obj){
    	String my_obj="",temp="";
		if(obj.indexOf("->")>-1){
			int idx = obj.indexOf("->"); 
			my_obj = obj.substring(idx+2);
		}else{
			my_obj = obj.substring(1);
		}
    	if("".equals(total_obj)){
    		total_obj = my_obj;
		}else{
				
				total_obj=total_obj+","+my_obj;
			
		}
    	return total_obj;
    }

    /**
     * 字段值为多个取得的总值过滤后的的所有值
     * @param obj_array
     * @return
     */
    private String getMultiTotal(String[] obj_array){
    	String my_obj="";
    	for(int i=0;i<obj_array.length;i++){
    		if("".equals(my_obj)){
    			my_obj = obj_array[i];
    		}else{
    			if(my_obj.indexOf(obj_array[i])>-1){}
    			else{
    				my_obj=my_obj+","+obj_array[i];
    			}
    			
    		}
    	}
		
    	return my_obj;
    }
    
    
    /**
     * 取得过滤后所有的附件id
     * @param total_obj
     * @param glfj_list
     * @param obj
     * @param object_filed
     * @param dj_fj
     * @param fj_tool
     * @return
     */
    private String gl_getFjTotalId(String total_obj,List<Map> glfj_list,String obj,String object_filed
    		,AnnexInfo dj_fj,AnnexTool fj_tool){
    	for(Map m : glfj_list){
    		String old_lfid = StringTool.checkString(m.get("LFID"));
    		AnnexInfo ai= fj_tool.getAnnex(old_lfid,obj,object_filed);
    		if(ai!=null){
	    		if(!(ai.getName()).equals(dj_fj.getName())){
					if("".equals(total_obj)){
						total_obj = ai.getID();
					}else{
						total_obj = total_obj+","+ai.getID();
					}
	    		}
    		}
		}
    	
    	return total_obj;
    }
    
    /**
     * 取得过滤后所有的附件
     * @param total_obj
     * @param glfj_list
     * @param obj
     * @param object_filed
     * @param dj_fj
     * @param fj_tool
     * @return
     */
    private List gl_getFjTotal(List<Map> glfj_list,String obj,String object_filed
    		,AnnexInfo dj_fj,AnnexTool fj_tool){
    	List fjlist = new ArrayList();
    	for(Map m : glfj_list){
    		String old_lfid = StringTool.checkString(m.get("LFID"));
    		AnnexInfo ai= fj_tool.getAnnex(old_lfid,obj,object_filed);
    		if(ai!=null){
	    		//if(!(ai.getName()).equals(dj_fj.getName())){
	    			fjlist.add(ai);
	    		//}
    		}
		}
    	
    	return fjlist;
    }
    
    /**
     * 过滤相同名称的附件后设置外键再copy附件
     * @param total_obj
     * @param foreign_id
     * @param fj
     * @param fj_tool
     * @throws AnnexTransactorException
     */
    private String get_gl_copyFj(String total_obj,String foreign_id,AnnexInfo fj,AnnexTool fj_tool) throws AnnexTransactorException{
    	String name = fj.getName();
    	if("".equals(total_obj)){
    		total_obj = name;
    		fj.setObjectID(foreign_id);
    		fj_tool.copyAnnex(fj);
    	}else{
    		if((";"+total_obj+";").indexOf(";"+name+";")==-1){
    			total_obj = total_obj +";"+name;
    			fj.setObjectID(foreign_id);
        		fj_tool.copyAnnex(fj);
    		}
    	}
    	return total_obj;
    }
    
    private String gl_getFjTotalIdLf(String total_obj,List<Map> glfj_list,String obj,String object_filed
    		,AnnexInfo dj_fj,DataTrimmerI trimmer){
    	for(Map m : glfj_list){
    		String old_lfid = StringTool.checkString(m.get("LFID"));
    		//AnnexInfo ai= fj_tool.getAnnex(old_lfid,obj,object_filed);
    		String sql = "SELECT * FROM XSYSTEM_ANNEX WHERE FK_ANNEX_ID=? AND ANNEX_OBJECT=? " +
    				"AND ANNEX_OBJECT_FIELD=?";
    		DataTrimmerI.DataItemList di_handlerlf = trimmer.createDIL();
    		di_handlerlf.set(old_lfid);
    		di_handlerlf.set(obj);
    		di_handlerlf.set(object_filed);
    		Map<String,String> hdlMap = trimmer.searchSingleData(sql, di_handlerlf);
    		if(hdlMap!=null){
    			String fj_name = StringTool.checkString(hdlMap.get("ANNEX_NAME"));
    			String fj_id = StringTool.checkString(hdlMap.get("XSYSTEM_ANNEX_ID"));
	    		if(!(fj_name).equals(dj_fj.getName())){
					if("".equals(total_obj)){
						total_obj = fj_id;
					}else{
						total_obj = total_obj+","+fj_id;
					}
	    		}
    		}
		}
    	
    	return total_obj;
    }
    
    /**
     * 克隆附件后设置外键
     * @param conn
     * @param trimmer
     * @param fjid
     * @param hid
     * @throws AnnexTransactorException
     */
    private void getHchFj(DataTrimmerI trimmer,String fjid,
    		String pkid,AnnexTool fj_tool) throws AnnexTransactorException{
    	
    	AnnexInfo my_fj = null;
		my_fj = (AnnexInfo)fj_tool.cloneAnnex(fjid);
		String update_fjSql = "UPDATE XSYSTEM_ANNEX SET FK_ANNEX_ID=? WHERE " +
				" XSYSTEM_ANNEX_ID=?";
		DataTrimmerI.DataItemList fj_dil = trimmer.createDIL();
		fj_dil.set(pkid);
		fj_dil.set(my_fj.getID());
		trimmer.execute(update_fjSql, fj_dil);
    }
    
    private void getHch_newFj(DataTrimmerI trimmer,String lfid,AnnexInfo my_fj){
    	
    	String update_fjSql = "UPDATE XSYSTEM_ANNEX SET FK_ANNEX_ID=? WHERE " +
				" XSYSTEM_ANNEX_ID=?";
		DataTrimmerI.DataItemList fj_dil = trimmer.createDIL();
		fj_dil.set(lfid);
		fj_dil.set(my_fj.getID());
		trimmer.execute(update_fjSql, fj_dil);
    }
    
    
    /**
     * 按各可选项统计查询
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward list4query(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        
    	Connection conn = null;
        
        CommonBean4HSQ req = new CommonBean4HSQ(request);

        Map param = req.getResource();

        String pageNO = StringTool.checkString(param.get("pageNO"));

        String DALEI = StringTool.checkString(param.get("DALEI"));        		//大类
        String XIAOLEI = StringTool.checkString(param.get("XIAOLEI"));	  		//小类
        String XILEI = StringTool.checkString(param.get("XILEI"));		  		//细类
        String XIXIANG = StringTool.checkString(param.get("XIXIANG"));    		//细项
        String XXLYID = StringTool.checkString(param.get("XXLYID"));      		//信息来源ID
        String LA = StringTool.checkString(param.get("LA"));  			  		//是否区立案
        String CLQKID = StringTool.checkString(param.get("CLQKID"));      		//处理情况ID
        String RCJD = StringTool.checkString(param.get("RCJD"));          		//日常接待
        String SFYJFW = StringTool.checkString(param.get("SFYJFW"));      		//是否越级访问
        String DBLXID = StringTool.checkString(param.get("DBLXID"));      		//督办类型ID
        String CLXSID = StringTool.checkString(param.get("CLXSID"));      		//处理形式ID
        String SFID = StringTool.checkString(param.get("SFID"));          		//身份ID
        String ZYCDID = StringTool.checkString(param.get("ZYCDID"));      		//信息重要程度ID
        String start_time = StringTool.checkString(param.get("start_time"));    //开始时间
        String end_time = StringTool.checkString(param.get("end_time"));        //结束时间
        
        
        

        request.setAttribute("dalei", DALEI);
        request.setAttribute("xiaolei", XIAOLEI);
        request.setAttribute("xilei", XILEI);
        request.setAttribute("xixiang", XIXIANG);
        request.setAttribute("XXLYID", XXLYID);
        request.setAttribute("LA", LA);
        request.setAttribute("CLQKID", CLQKID);
        request.setAttribute("RCJD", RCJD);
        request.setAttribute("SFYJFW", SFYJFW);
        request.setAttribute("DBLXID", DBLXID);
        request.setAttribute("CLXSID", CLXSID);
        request.setAttribute("SFID", SFID);
        request.setAttribute("ZYCDID", ZYCDID);
        request.setAttribute("start_time", start_time);
        request.setAttribute("end_time", end_time);
        
        IUser user = ISystem.getSessionUser(request);

        StringBuffer where = new StringBuffer("  AND D.LFBS='0' ");
        
        if (!DALEI.equals("")) {
            where.append(" AND D.NRNAME LIKE '%"+DALEI+"%'");
        }
        if (!XIAOLEI.equals("")) {
            where.append(" AND D.NRNAME LIKE '%"+DALEI+"->"+XIAOLEI+"%'");
        }
        if (!XILEI.equals("")) {
            where.append(" AND D.NRNAME LIKE '%"+DALEI+"->"+XIAOLEI+"->"+XILEI+"%'");
        }
        if (!XIXIANG.equals("")) {
        	where.append(" AND D.NRNAME LIKE '%"+DALEI+"->"+XIAOLEI+"->"+XILEI+"->"+XIXIANG+"%'");
        }
        if (!XXLYID.equals("")) {
            where.append(" AND D.XXLYID = '"+XXLYID+"'");
        }
        if (!LA.equals("")) {
            where.append(" AND D.LA = '"+LA+"'");
        }
        if (!CLQKID.equals("")) {
            where.append(" AND D.CLQKID = '"+CLQKID+"'");
        }
        if (!RCJD.equals("")) {
            where.append(" AND D.RCJD = '"+RCJD+"'");
        }
        if (!SFYJFW.equals("")) {
            where.append(" AND D.SFYJFW = '"+SFYJFW+"'");
        }
        if (!DBLXID.equals("")) {
            where.append(" AND D.DBLXID = '"+DBLXID+"'");
        }
        if (!CLXSID.equals("")) {
            where.append(" AND D.DBLXID = '"+CLXSID+"'");
        }
        if (!SFID.equals("")) {
            where.append(" AND D.DBLXID = '"+SFID+"'");
        }
        if (!ZYCDID.equals("")) {
            where.append(" AND D.DBLXID = '"+ZYCDID+"'");
        }
        if (!start_time.equals("") && !end_time.equals("")) {
            where.append(" AND '"+start_time+"' <= D.XFTIME <= '"+end_time+"'");
        }
        if (!start_time.equals("") && end_time.equals("")) {
            where.append(" AND D.XFTIME >= '"+start_time+"'");
        }
        if (start_time.equals("") && !end_time.equals("")) {
            where.append(" AND D.XFTIME <= '"+end_time+"'");
        }
        
        
        where.append("  ORDER BY A.OBJ_CREATETIME DESC");
        String sql1="",sql2="";

        sql1 = "SELECT COUNT(*) as num  FROM ISYS_OBJECT A," +
        		"(SELECT DISTINCT(A0.ID) FROM " +
        		"(SELECT DISTINCT(ISYS_OBJECT.ID) FROM " +
        		"ISYS_OBJECT LEFT JOIN ISYS_OBJECT_RELATION ON " +
        		"ISYS_OBJECT.ID = ISYS_OBJECT_RELATION.ID LEFT JOIN APP_LF ON " +
        		"ISYS_OBJECT_RELATION.OBJ_PKID = APP_LF.LFID " +
        		"WHERE ISYS_OBJECT_RELATION.OBJ_TABLE = 'APP_LF' AND OBJ_KEY = 'APP_LFDJ' AND LFTYPE = 0 ) A0, " +
        		"(SELECT DISTINCT(ISYS_OBJECT.ID) FROM ISYS_OBJECT LEFT JOIN ISYS_OBJECT_RELATION ON " +
        		"ISYS_OBJECT.ID = ISYS_OBJECT_RELATION.ID LEFT JOIN APP_XFHANDLER ON " +
        		"ISYS_OBJECT_RELATION.OBJ_PKID = APP_XFHANDLER.HID WHERE ISYS_OBJECT_RELATION.OBJ_TABLE = 'APP_XFHANDLER' " +
        		"AND OBJ_KEY = 'APP_LFDJ' AND H_GROUPID = '"+(user.igroup()).id()+"' ) A1 WHERE A0.ID = A1.ID ) B," +
        		"ISYS_OBJECT_RELATION C, APP_LF D WHERE C.OBJ_TABLE = 'APP_LF' AND C.OBJ_PKID = D.LFID AND " +
        		"A.ID = C.ID AND A.ID = B.ID "+ where.toString(); 
        
        sql2 = "SELECT D.*  FROM ISYS_OBJECT A," +
		"(SELECT DISTINCT(A0.ID) FROM " +
		"(SELECT DISTINCT(ISYS_OBJECT.ID) FROM " +
		"ISYS_OBJECT LEFT JOIN ISYS_OBJECT_RELATION ON " +
		"ISYS_OBJECT.ID = ISYS_OBJECT_RELATION.ID LEFT JOIN APP_LF ON " +
		"ISYS_OBJECT_RELATION.OBJ_PKID = APP_LF.LFID " +
		"WHERE ISYS_OBJECT_RELATION.OBJ_TABLE = 'APP_LF' AND OBJ_KEY = 'APP_LFDJ' AND LFTYPE = 0 ) A0, " +
		"(SELECT DISTINCT(ISYS_OBJECT.ID) FROM ISYS_OBJECT LEFT JOIN ISYS_OBJECT_RELATION ON " +
		"ISYS_OBJECT.ID = ISYS_OBJECT_RELATION.ID LEFT JOIN APP_XFHANDLER ON " +
		"ISYS_OBJECT_RELATION.OBJ_PKID = APP_XFHANDLER.HID WHERE ISYS_OBJECT_RELATION.OBJ_TABLE = 'APP_XFHANDLER' " +
		"AND OBJ_KEY = 'APP_LFDJ' AND H_GROUPID = '"+(user.igroup()).id()+"' ) A1 WHERE A0.ID = A1.ID ) B," +
		"ISYS_OBJECT_RELATION C, APP_LF D WHERE C.OBJ_TABLE = 'APP_LF' AND C.OBJ_PKID = D.LFID AND " +
		"A.ID = C.ID AND A.ID = B.ID "+ where.toString();
            //" ORDER BY  WJJS.WJTIME ASC";

        String url = request.getContextPath() + "/app/lfbl.do?method=list4query";

        try {
            SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();

            QueryJack plus = QueryJackFactory.getInstance().createQueryJack(false);

            // ����
            plus.setParameter(QueryJackFactory.PAGINATION_SQL1, sql1);
            plus.setParameter(QueryJackFactory.PAGINATION_SQL2, sql2);
            plus.setParameter(QueryJackFactory.DATABASE_CONNECTION, conn);
            plus.setParameter(QueryJackFactory.PAGINATION_LINKSTRING, url);
            plus.setParameter(QueryJackFactory.PAGINATION_COUNT, "20");
            plus.setParameter(QueryJackFactory.PAGINATION_PAGENO, pageNO);

            // plus.setParameter(QueryJackFactory.PAGINATION_UPDATEPAGENO, "");
            List resultList = plus.work();

            

            // �����ת����
            Controller controller = plus.getController("form1");

            // ���õ�ת����
            controller.setType("input");

            // ��ʾ��ǩ
            Label label = plus.getLabel();

            // ������ʾ��ǩ����
            label.setType("href");

            Object[] result = new Object[4];
            result[0] = resultList;
            result[1] = label;
            result[2] = controller;
            result[3] = pageNO;
            
            request.setAttribute("result", result);
        } catch (Exception ex) {
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }

        return mapping.findForward("list4query");
    }
    
    public ActionForward getNrfl(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception{
    	Connection conn = null;
    	
		CommonBean4HSQ req = new CommonBean4HSQ(request);
		Map param = req.getResource();
		String id = StringTool.checkString(param.get("id"));
		String sql="SELECT * FROM ISYS_DATAINDEX WHERE DI_PARENT=?";
		List<Map>  resultList = null;
    	try{
    		SystemDataSource ds = SystemDataSource.getInstance();
            conn = ds.getConnection();
            DataTrimmerI trimmer = new DataTrimmerI(conn);
            DataTrimmerI.DataItemList dil = trimmer.createDIL();
            if("".equals(id)){
            	id = "880302";
            }
            dil.set(id);
            resultList= trimmer.searchMultiData(sql, dil);
            String out = this.getJson(resultList.toArray());
            response.setCharacterEncoding("UTF-8"); 
	   		PrintWriter pw = response.getWriter();
	   		pw.write(this.print_Json(resultList.toArray()));
	   		//pw.write("<input type=hidden id='xf_list' value='"+this.print_Json(resultList.toArray())+"'>");
	   		pw.flush();
            
    	}catch (Exception ex) {
            ISystem.catchException(request, this, ex);
        } finally {
            SystemDataSource.closeConnection(conn);
        }
    	return mapping.findForward("list4query");
    }
    
    
    public String getJson(Object[] array){
		
		 return this.array2Json(array);
	}
	
	public String print_Json(Object o){
		
		 return this.toJson(o);
	}
	
	public static String toJson(Object o) { 
	    if (o==null) 
	        return "null"; 
	    if (o instanceof String) 
	        return string2Json((String)o); 
	    if (o instanceof Boolean) 
	        return boolean2Json((Boolean)o); 
	    if (o instanceof Number) 
	        return number2Json((Number)o); 
	    if (o instanceof Map) 
	        return map2Json((Map<String, Object>)o); 
	    if (o instanceof Object[]) 
	        return array2Json((Object[])o); 
	    throw new RuntimeException("Unsupported type: " + o.getClass().getName()); 
	 } 
	static String string2Json(String s) { 
	    StringBuilder sb = new StringBuilder(s.length()+20); 
	    sb.append('\"'); 
	    for (int i=0; i<s.length(); i++) { 
	        char c = s.charAt(i); 
	        switch (c) { 
	        case '\"': 
	            sb.append("\\\""); 
	            break; 
	        case '\\': 
	            sb.append("\\\\"); 
	            break; 
	        case '/': 
	            sb.append("\\/"); 
	            break; 
	        case '\b': 
	            sb.append("\\b"); 
	            break; 
	        case '\f': 
	            sb.append("\\f"); 
	            break; 
	        case '\n': 
	            sb.append("\\n"); 
	            break; 
	        case '\r': 
	            sb.append("\\r"); 
	            break; 
	        case '\t': 
	            sb.append("\\t"); 
	            break; 
	        default: 
	            sb.append(c); 
	        } 
	    } 
	    sb.append('\"'); 
	    return sb.toString(); 
	 } 
	static String boolean2Json(Boolean bool) { 
	    return bool.toString(); 
	 } 
	static String array2Json(Object[] array) { 
	    if (array.length==0) 
	        return "[]"; 
	    StringBuilder sb = new StringBuilder(array.length << 4); 
	    sb.append('['); 
	    for (Object o : array) { 
	        sb.append(toJson(o)); 
	        sb.append(','); 
	    } 
	    // 将最后添加的 ',' 变为 ']': 
	    sb.setCharAt(sb.length()-1, ']'); 
	    return sb.toString(); 
	 } 
	static String map2Json(Map<String, Object> map) { 
	    if (map.isEmpty()) 
	        return "{}"; 
	    StringBuilder sb = new StringBuilder(map.size() << 4); 
	    sb.append('{'); 
	    Set<String> keys = map.keySet(); 
	    for (String key : keys) { 
	        Object value = map.get(key); 
	        sb.append('\"'); 
	        sb.append(key); 
	        sb.append('\"'); 
	        sb.append(':'); 
	        sb.append(toJson(value)); 
	        sb.append(','); 
	    } 
	    // 将最后的 ',' 变为 '}': 
	    sb.setCharAt(sb.length()-1, '}'); 
	    return sb.toString(); 
	 } 
	static String number2Json(Number number) { 
	    return number.toString(); 
	 }
    
    
    
}
